package server.io.game.fact.hall;

import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;

import server.io.game.fact.Fact_Scene;
import server.io.game.fact.room.Room_Base;
import server.io.game.fact.room.Room_Can;
import server.io.game.fact.room.Room_Normal;
import server.io.game.fact.user.User_Base;
import server.io.game.fact.user.User_Normal;
import server.io.pro.bean.Pro_JoinHall;
import server.io.pro.bean.Pro_JoinRoom;
import server.io.pro.ctrl.Pro_Adapter_Base;

public abstract class Hall_Base extends Fact_Scene implements Hall_Inter
{

	public String type;

	public int room_amount;

	public int room_size;

	public int user_amount;

	public int user_size;
	// 房间
	public Room_Can rooms = null;

	public Hall_Base()
	{
		// TODO Auto-generated constructor stub
		this.nat_sceneName = "hall";
	}

	public Hall_Base(int id, String fact_id, String fact_type)
	{
		super(id, fact_id, fact_type);
		this.nat_sceneName = "hall";
	}

	@Override
	public void init()
	{
		// 暂时写死初始化一些玩家而已 以后没有这些
		Room_Normal[] _rooms = new Room_Normal[4];
		for (int i = 0; i < _rooms.length; i++)
		{
			_rooms[i] = new Room_Normal(i);
		}
		this.rooms.setAll(_rooms);
	}

	/**
	 * 玩家加入房间
	 * 
	 * @param sKey
	 * @param room_number
	 * @return
	 */
	public Room_Base joinRoom(SelectionKey sKey, int room_number)
	{
		 Room_Base _room = this.rooms.findData(room_number);
		 _room.join(sKey);
		return _room;
	}

	// ///////////////////////////////////

	/**
	 * 网络数据控制中枢
	 * 
	 * @param content
	 * @param key
	 */
	@Override
	public void control(int aStrId, String aStr, SelectionKey key)
	{
		// TODO Auto-generated method stub
		super.control(aStrId, aStr, key);
		byte[] _send = null;
		String _order = "one";
		switch (aStrId)
		{
		// 进入房间
		case 1061:
			Pro_JoinRoom _joinRoom = new Pro_JoinRoom();
			_joinRoom._recv = Pro_Adapter_Base.jsonToObject(aStr,
					Pro_JoinRoom.Recv.class);
			int _roomNum = _joinRoom._recv.room_number;
			Room_Base _room = this.joinRoom(key, _roomNum);
			_joinRoom._send = _joinRoom.new Send(_room);
			_send = nat_mProAdp_Send.encapProtocol(_joinRoom._send);
			break;
		default:
			break;
		}

		this.send(_send, _order, key);
	}

}
